package com.stack.common.utils.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 
 * @author linxinze
 *
 */
public class ThreadPoolUtil {

	private static ThreadPoolExecutor threadPoolExecutor = null;
	
	static {
		//创建等待队列
        BlockingQueue<Runnable> blockingQueue=new ArrayBlockingQueue<>(100);

        /**
         * corePoolSize -池中所保存的线程数，包括空闲线程
         * maximumPoolSize -池中允许的最大线程数
         * keepAliveTime -当线程数大于核心时，此为终止前多余的空闲线程等待新任务的最长时间
         * unit -keepAliveTime参数的时间单位
         * orkQueue -执行前用于保持任务的队列。此队列仅保持由execute方法提交的Runnable任务
         */
         threadPoolExecutor = new ThreadPoolExecutor(100,200,2000,TimeUnit.MILLISECONDS,blockingQueue);
	}
	
	private ThreadPoolUtil () {
		
	}
	
	/**
	 * 自定义线程池
	 * @return
	 */
	public static ThreadPoolExecutor getUserDefinedThreadPool() {
		return threadPoolExecutor;
	}
}
